package com.duobaoyu.dby.supply.api.service.impl;

import com.duobaoyu.dby.channel.adapter.enums.biz.config.GlobalErrorCodeEnum;
import com.duobaoyu.dby.supply.api.service.RechargeInfoBizService;
import com.duobaoyu.dby.supply.biz.client.boundary.account.AccountBoundaryClient;
import com.duobaoyu.dby.supply.biz.client.boundary.account.bean.bo.OperatorInfoBO;
import com.duobaoyu.dby.supply.biz.client.boundary.account.bean.dto.OperatorInfoDTO;
import com.duobaoyu.dby.supply.common.biz.remote.dto.rechargeinfo.PhoneOperatorQueryDTO;
import com.duobaoyu.dby.supply.common.biz.remote.to.rechargeinfo.PhoneOperatorTO;
import com.duobaoyu.dby.supply.core.common.exception.CustomAssert;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * 充值信息业务实现
 *
 * @Author yangyong
 * @Date 2023/9/27
 */
@Service
@RequiredArgsConstructor
public class RechargeInfoBizServiceImpl implements RechargeInfoBizService {

	private final AccountBoundaryClient accountBoundaryClient;

	@Override
	public PhoneOperatorTO queryPhoneOperator(PhoneOperatorQueryDTO operatorQuery) {
		OperatorInfoDTO dto = OperatorInfoDTO.builder()
				.channelCode(operatorQuery.getChannelCode())
				.phoneNo(operatorQuery.getPhone())
				.build();
		OperatorInfoBO operatorInfo = accountBoundaryClient.phoneOperatorInfo(dto);
		CustomAssert.notNull(operatorInfo, GlobalErrorCodeEnum.CHANNEL_NOT_SUPPORT_QUERY_PHONE_OPERATOR);
		return PhoneOperatorTO.builder()
				.operatorName(operatorInfo.getOperatorName())
				.operatorType(operatorInfo.getOperatorType())
				.provinceName(operatorInfo.getChannelProvinceName())
				.cityName(operatorInfo.getChannelCityName())
				.isTransfer(operatorInfo.getIsTransfer())
				.build();
	}
}
